import { mongo } from "../mogoConfig"

const run = async () => {

    const theaterTB = mongo.db("sample_mflix").collection("theaters")

    let cursor = theaterTB.find({
        "location.geo": {
            $near: {
                $geometry: { type: "Point", coordinates: [-73.9667, 40.78] },
                $maxDistance: 10000
            }
        }
    }).project({ "location.geo": 0 })
    console.log("geo查询1------------------------------")
    for await (const item of cursor) {
        console.log(JSON.stringify(item))
    }

    cursor = theaterTB.find({
        "location.geo": {
            $geoWithin: {
                $geometry: {
                    type: "Polygon", coordinates: [
                        [
                            [-72, 40], // Polygon coordinates defining the range
                            [-74, 41],
                            [-72, 39],
                            [-72, 40],
                        ],
                    ],
                }
            }
        }
    }).project({ "location.geo": 0 })
    console.log("geo查询2------------------------------")
    for await (const item of cursor) {
        console.log(JSON.stringify(item))
    }




}


run()
    .catch(error => {
        console.log(error)
    })
    .finally(() => {
        mongo.close()
        console.log("执行结束")
    })